package com.telrob.antlr.type;

import java.util.ArrayList;
import java.util.List;

public class FunctionCallParamType extends XnType {
	private List<XnType>list=new ArrayList<XnType>();
	
	public void add(XnType item) {
		list.add(item);
	}
	public List<XnType> getList() {
		return list;
	}

	public void setList(List<XnType> list) {
		this.list = list;
	}
	@Override
	public String toString() {
		return "FunctionCallParamType [list=" + list + "]";
	}
	
	
	@Override
	public void process() {
		if(list!=null&&list.size()>0) {
			int size=list.size();
			for(int i=size-1;i>=0;i--) {
				XnType item=list.get(i);
				if(item instanceof ExpressionType) {
					eachExpression((ExpressionType)item, code);
					code.append("push dx\r\n");
				}else if(item instanceof DigitType) {
					String value=((DigitType)item).getValue();
					code.append("movrn dx,"+value+"\r\n");
					code.append("push dx\r\n");
				}else if(item instanceof IdType){
					String name=((IdType)item).getName();
					SymbolType sym=getSymbol(name);
					if(sym==null) {
						System.err.println("不能找到改参数定义"+name);
						System.exit(0);
					}
					if(sym.getType()==1) {
						code.append("loadd dx,"+name+"\r\n");
					}else if(sym.getType()==4){
						//当是字符串时候
						code.append("movrn dx,"+name+"\r\n");
					}else {
						code.append("loads dx,"+sym.getIndex()+"\r\n");
					}
					code.append("push dx\r\n");
				}
			}
			
			code.append("movrn ax,"+size+"\r\n");
		}
	}
	
}
